package com.es.test.controller;


import com.es.test.service.UserLabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;


/**
 * @author django
 * @date 2024/1/29
 * @description TODO
 */
@Slf4j
@RestController
public class UserDataController {
    @Autowired
    private UserLabelService userLabelService;


    @RequestMapping("insert")
    public String insert(int start, int end, int threadNum) {
        userLabelService.generateData(start, end, threadNum);
        return "success";
    }

    @RequestMapping("operate")
    public String operate(int type) {
        clear();
        userLabelService.operate(type);
        return "success";
    }

    @RequestMapping("operate_multi-thread")
    public String multiThread(int threadNum, int index, int type) {
        clear();
        userLabelService.multiThread(threadNum, index, type);
        return "success";
    }

    @RequestMapping("complex_query")
    public String complex() {
        clear();
        userLabelService.complex();
        return "success";
    }

    @RequestMapping("complex__multi-thread")
    public String complexMultiThread(int threadNum, int len, int type, int qtype) {
        clear();
        userLabelService.complexMultiThread(threadNum, len, type, qtype);
        return "success";
    }

    @RequestMapping("redisbitmap")
    public String redisBitMap() {
        clear();
        userLabelService.redisBitMap();
        return "success";
    }


    @RequestMapping("query-one-page")
    public String qop(int threadNum, int len, int type, int qtype) {
        clear();
        userLabelService.qop(threadNum, len, type, qtype);
        return "success";
    }
    private void clear() {
        userLabelService.atomicLong.set(0);
        userLabelService.timeLong.set(0);
        userLabelService.nLong.set(0);
        userLabelService.wLong.set(0);

    }
}
